﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Deployment.Application;
using System.Windows.Forms;
using System.ComponentModel;

namespace Cash
{
    public class Updater
    {

        public void Update()
        {
            if (ApplicationDeployment.IsNetworkDeployed)
            {
                MessageBox.Show("ffff");
                _application.CheckForUpdateCompleted +=new CheckForUpdateCompletedEventHandler(CheckForUpdateCompleted);
                _application.UpdateProgressChanged += new DeploymentProgressChangedEventHandler(UpdateProgressChanged);
                _application.UpdateCompleted += new AsyncCompletedEventHandler(UpdateCompleted);

                _application.CheckForUpdate();
                MessageBox.Show("ffff");
            }
        }

        #region Helper

        private void CheckForUpdateCompleted(object sender, CheckForUpdateCompletedEventArgs e)
        {
            if (e.UpdateAvailable)
                _application.UpdateAsync();
        }
        private void UpdateProgressChanged(object sender, DeploymentProgressChangedEventArgs e)
        {
            MessageBox.Show("update");
        }
        private void UpdateCompleted(object sender, AsyncCompletedEventArgs e)
        {
            Application.Restart();
        }

        #endregion

        #region Fields

        private ApplicationDeployment _application = ApplicationDeployment.CurrentDeployment;
        
        #endregion
    }
}
